package com.eleadmin.order.controller;

import com.eleadmin.damon.utils.results.PageResult2;
import com.eleadmin.common.core.web.*;
import com.eleadmin.common.core.annotation.OperationLog;
import com.eleadmin.order.entity.WriteOff;
import com.eleadmin.order.service.WriteOffService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.apache.poi.ss.formula.functions.T;


/**
 *
 * 对账管理
 * @author : Doman
 * @date : 2023-08-11 16:47:23
 * @version ：1.0
 */

@Api(tags = "对账管理")
@RestController
@RequestMapping("/api/order/writeOff")
public class WriteOffController extends BaseController {

    @Autowired
    private WriteOffService writeOffService;

    @PreAuthorize("hasAuthority('order:writeOff:list')")
    //@ApiOperation("分页查询对账管理")
    @GetMapping("/page")
    public JsonResult page(PageResult2<T> page, WriteOff writeOff) throws Exception{
        return writeOffService.list(page, writeOff, getLoginUser());
    }

    @PreAuthorize("hasAuthority('order:writeOff:list')")
    //@ApiOperation("查询全部对账管理")
    @GetMapping()
    public JsonResult list(WriteOff writeOff){
        return writeOffService.list(writeOff, getLoginUser());
    }

    @PreAuthorize("hasAuthority('order:writeOff:list')")
    //@ApiOperation("根据id查询对账管理")
    @GetMapping("/{id}")
    public JsonResult get(@PathVariable("id") String id) {
        return writeOffService.getById(id);
    }


    @PreAuthorize("hasAuthority('order:writeOff:save')")
    @OperationLog
    @ApiOperation(value ="添加对账管理")
    @PostMapping()
    public JsonResult save(@RequestBody WriteOff writeOff) {
        try {
            return writeOffService.save(writeOff, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }

    }

    @PreAuthorize("hasAuthority('order:writeOff:update')")
    @OperationLog
    @ApiOperation(value ="修改对账管理")
    @PutMapping()
    public JsonResult update(@RequestBody WriteOff writeOff) {
        try {
            return writeOffService.update(writeOff, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

    @PreAuthorize("hasAuthority('order:writeOff:update')")
    @OperationLog
    @ApiOperation(value ="修改状态")
    @PutMapping("updateState")
    public JsonResult updateState(@RequestBody WriteOff writeOff) {
        try {
            return writeOffService.updateState(writeOff, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }
    @PreAuthorize("hasAuthority('order:writeOff:update')")
    @OperationLog
    @ApiOperation(value ="收款确认")
    @PutMapping("receiveState")
    public JsonResult receiveState(@RequestBody WriteOff writeOff) {
        try {
            return writeOffService.receiveState(writeOff, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

    @PreAuthorize("hasAuthority('order:writeOff:remove')")
    @OperationLog
    @ApiOperation(value ="删除对账管理")
    @DeleteMapping("/{id}")
    public JsonResult remove(@PathVariable("id") String id) {
        try {
            return writeOffService.remove(id, getLoginUser());
        } catch (Exception e) {
            return JsonResult.error(e.getMessage());
        }
    }

}
